package com.pan.framework.core.aop.entiy;

import java.util.ArrayList;
import java.util.List;

public class MyCutArgs {

    List<MyCutParam> argList;

    public MyCutArgs(Class[] types,Object[] args) {
        argList = new ArrayList<>();
        if (types.length == 0){
            return;
        }
        for (int i = 0; i < args.length; i++) {
            MyCutParam myCutParam = new MyCutParam(i, types[i], args[i]);
            argList.add(myCutParam);
        }
    }
    public int getLength(){
        return argList.size();
    }
    public MyCutParam getParamByOrder(int index){
        return argList.get(index);
    }
    public List<MyCutParam> getArgList(){
        return argList;
    }
    public void resetArg(int index,Object obj){
        MyCutParam myCutParam = argList.get(index);
        myCutParam.setArg(obj);
    }
    public void resetArgs(Object[] args){
        for (int i = 0; i < args.length; i++) {
            argList.get(i).setArg(args);
        }
    }
    public Object[] getArgs(){
        if (argList.size()==0){
            return new Object[0];
        }
        return argList.stream().map(MyCutParam::getArg).toArray();
    }

    @Override
    public String toString() {
        return argList.stream().map(MyCutParam::toString).reduce("[",(x,y)->x+", "+y)+"]";
    }
}
